package com.shizhanzhe.zxbapp.task.newshare;

import android.annotation.SuppressLint;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;

import com.shizhanzhe.zxbapp.R;
import com.shizhanzhe.zxbapp.url.Path;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by zz9527 on 2019/3/18.
 */
public class WebRecyclerAdapter extends RecyclerView.Adapter<WebRecyclerAdapter.ViewHolder> {
    private Context mContext;
    private List<ShareDetail.RetuiBean> mData = new ArrayList<>();

    public WebRecyclerAdapter(Context context) {
        mContext = context;
    }

    public void updateData(int page, List<ShareDetail.RetuiBean> dataSet) {
        if (dataSet != null && !dataSet.isEmpty()) {
            if (page == 1) {
                mData = dataSet;
            } else {
                mData.addAll(dataSet);
            }
            notifyDataSetChanged();
        }
    }

    @NonNull
    @Override
    public WebRecyclerAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.adapter_lv_sharenew, parent, false);
        return new ViewHolder(view);
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(@NonNull WebRecyclerAdapter.ViewHolder holder, final int position) {
        ShareDetail.RetuiBean bean = mData.get(position);
        Glide.with(mContext).load(Path.img(bean.getIcon())).apply(new RequestOptions().error(R.mipmap.logo)).into(holder.img);
        holder.title.setText(bean.getAname());
        holder.type.setText(bean.getClassX());
        holder.red.setText(Html.fromHtml("<font color=\"#ffffff\">已发放</font><font color=\"#FF0000\">"+bean.getTotal()+"</font><font color=\"#ffffff\">元</font>"));
            holder.one.setText(bean.getPrice() + "");
            holder.two.setText(bean.getVipprice() + "");
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mItemClickListener.onItemClick(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.share_img)
        ImageView img;
        @BindView(R.id.tv_share_title)
        TextView title;
        @BindView(R.id.type)
        TextView type;
        @BindView(R.id.red)
        TextView red;
        @BindView(R.id.tv)
        TextView one;
        @BindView(R.id.tv2)
        TextView two;
        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
    private ItemClickListener mItemClickListener ;
    public interface ItemClickListener{
        public void onItemClick(int position) ;
    }
    public void setOnItemClickListener(ItemClickListener itemClickListener){
        this.mItemClickListener = itemClickListener ;

    }
}
